package cn.bellychang.queue.liuxin;

import cn.bellychang.arraylist.liuxin.ArrayList;
import cn.bellychang.iiterface.bobo.Queue;

/**
 * FIFO
 *
 * array[0] out  array[getSize] in
 *
 * @author: bellychang
 * @date: 2020/2/7
 */
public class ArrayQueue<E> implements Queue<E> {

    private ArrayList<E> array;

    public ArrayQueue() {
        this.array = new ArrayList<>(1);
    }

    @Override
    public void enqueue(E e) {
        array.addLast(e);
    }

    @Override
    public E dequeue() {
        return array.remove(0);
    }

    @Override
    public E getFront() {
        return array.get(0);
    }

    @Override
    public boolean isEmpty() {
        return array.getSize() == 0;
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public String toString() {
        return "ArrayQueue Head {" + array + "} Tail";
    }
}
